#include "admin.h"
#include <stdio.h>
#include "parser.tab.h"


Util::Util()
{
}

std::string Util::GetSpace()
{
	return "    ";
}

std::string Util::AddSpace(std::string str)
{
	int i;
	int len;
	std::string dststr;
	std::string space = GetSpace();

	dststr += space;
	len = str.length();
	for(i = 0; i < len; i++) {
		dststr += str[i];
		if ((i + 1) == len) {
			continue;
		}
		if (str[i] == '\n') {
			dststr += space;
		}
	}

	return dststr;
}





/******************************TypeStat*************************************************/
TypeStat::TypeStat()
{
}

void TypeStat::Reset()
{
	v.clear();
}

void TypeStat::AddTypeItem(TypeItem item)
{
	TypeItem *dst = GetTypeItem(item.name);
	if (!dst) {
		v.push_back(item);
	}
}

void TypeStat::AddTypeItem(std::string name, int key)
{
	AddTypeItem(TypeItem(name, key));
}

TypeItem *TypeStat::GetTypeItem(std::string name)
{
	int i;

	for (i = 0; i < (int)v.size(); i++) {
		if (v[i].name == name) {
			return &v[i];
		}
	}

	return NULL;
}